package com.eat.fish_service.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.eat.common_utils.R;
import com.eat.common_utils.ResultCode;
import com.eat.fish_service.entity.Dao.UserAquarium;
import com.eat.fish_service.mapper.UserAquariumMapper;
import com.eat.fish_service.service.UserAquariumService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author LWB
 * @since 2022-03-31
 */
@Service
@Slf4j
public class UserAquariumServiceImpl extends ServiceImpl<UserAquariumMapper, UserAquarium> implements UserAquariumService {

    @Override
    public R aquariumIdList(String username) {

        List<UserAquarium> userAquariumList = baseMapper.selectList(new QueryWrapper<UserAquarium>().eq("username", username));

        List<Long> list = new ArrayList();

        for (UserAquarium userAquarium : userAquariumList) {
            list.add(userAquarium.getAquariumId());
        }


        if(list.size() == 0){
            //表示该用户没有添加鱼缸
            return R.ok().code(ResultCode.NO_AQUARIUM).message("该用户没有添加鱼缸");
        }else {
            return R.ok().data("userAquariumList",list);
        }

    }
}
